from flask import Blueprint, jsonify, request
from models import Image
from flask_jwt_extended import jwt_required, get_jwt_identity
from utils.response import success_response,error_response

api = Blueprint('image_api', __name__)

@api.route('/', methods=['GET'])
@jwt_required()
def get_images():
    page = request.args.get('page', default=1, type=int)
    limit = request.args.get('limit', default=10, type=int)

    query = Image.query.order_by(Image.id)
    pagination = query.paginate(page=page, per_page=limit, error_out=False)
    for i in pagination.items:
        a = i.to_dict()
        print(a)
    return jsonify({
        "code": 0,
        "msg": "查询成功",
        "page": page,
        "limit": limit,
        "count": pagination.total,
        "data": [i.to_dict() for i in pagination.items]
    })
